home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 14 / Hot Mix 14.iso / HTML / vendors / finesse / InstallIt2 < prev    next >
Text File  |  1996-07-10  |  11KB  |  367 lines

  1. #!/bin/csh -f
  2.  
  3. #   This is an example installation script for HotMix.
  4. #
  5. #   The bulk of the code in this script is aimed at determining the
  6. #   INST_PATH -- the place to install the software (this isn't as
  7. #   easy as it might initially seem!).  The default is to copy to an
  8. #   installation directory in /usr/tmp.  If /usr/tmp doesn't exist,
  9. #   there is not enough disk space, or the user prefers another directory,
  10. #   the script will ask for another directory name.  In this case,
  11. #   the script will read the desired directory name, check its validity,
  12. #   check the available disk space, and if everything is OK, will then
  13. #   do the installation.
  14. #
  15. #   To customize the script, you will need to change these 4 parameters:
  16. #
  17. #       MYAPP = name of the application
  18. #
  19. #       INST_DIR = name of the installation directory
  20. #                  (this is the directory name, not the full path name)
  21. #       CD_PATH = directory path of the location of the software
  22. #                 on the HotMix CD-ROM (it must begin with "$HOTMIXDIR",
  23. #                 which is the mount point for the CD-ROM drive).
  24. #       KBYTES_REQ = required size of the full installation (in Kbytes).
  25. #
  26. #   In this simple example, the installation just involves copying
  27. #   the software to the hard disk, and then launching the application.
  28. #   In other cases, the installation will probably be more complicated,
  29. #   so you'll need to change the code at the end of the script as well.
  30. #   The rest of the script should not require modification.
  31. #
  32. #   All of the InstallIt and RemoveIt scripts should reside in the
  33. #   $CD_PATH directory.
  34. #
  35. #
  36. #
  37. #
  38.  
  39. set MYAPP=finesse
  40. set INST_DIR=finesse
  41. set CD_PATH=$HOTMIXDIR/HTML/vendors/finesse
  42. set KBYTES_REQ=3000
  43.  
  44. #
  45. #  Test to see if on the new Indy filesystem or old one.
  46. #
  47.  
  48. set TEST_NEW=`df -k /usr | /usr/bin/awk '{print $7}'`
  49.  
  50. if ( "$TEST_NEW" == "Mounted /" ) then
  51.    set FILE_STRUCTURE=new
  52.  
  53. else
  54.    set FILE_STRUCTURE=old
  55. endif
  56.  
  57.  
  58. #
  59. #  Determine the INST_PATH name.
  60. #
  61. #  First try /usr/tmp;  then if necessary, ask for another directory.
  62. #
  63.  
  64. @ MBYTES_REQ = ($KBYTES_REQ) / 1000
  65.  
  66. if ( $FILE_STRUCTURE == "new" ) then
  67.    set KBYTES_AVAIL=`df -k / | /bin/grep / | /usr/bin/awk '{print $5}'`
  68. else
  69.    set KBYTES_AVAIL=`df -k /usr | /bin/grep /usr | /usr/bin/awk '{print $5}'`
  70. endif
  71.  
  72.  
  73. if ( -w /usr/tmp ) then
  74.  
  75.     if ( $KBYTES_AVAIL > $KBYTES_REQ ) then
  76.  
  77.         set INST_PATH=/usr/tmp/$INST_DIR
  78.  
  79.         echo " "
  80.         echo "The installation of finesse requires $MBYTES_REQ Mbytes of disk space."
  81.         echo " "
  82.         echo "It will be installed in a directory named $INST_PATH"
  83.         echo "Is this OK (y/n)?  \c"
  84.         set ans=($<)
  85.         if ( $ans != 'y' ) then
  86.             echo " "
  87.             echo "Do you want to install in another directory (y/n)?  \c"
  88.             set ans2=($<)
  89.             if ( $ans2 != 'y' ) then
  90.                 echo " "
  91.                 echo "... Bye."
  92.                 sleep 3
  93.                 exit
  94.             else
  95.                 set INST_PATH=none
  96.             endif
  97.         else
  98.             if ( -d $INST_PATH ) then
  99.                 echo " "
  100.                 echo "It seems the demo is already installed.  Continue anyway (y/n)?  \c"
  101.                 set ans3=($<)
  102.                 if ( $ans3 != 'y' ) then
  103.                     echo " "
  104.                     echo "... Bye."
  105.                     sleep 3
  106.                     exit
  107.                 endif
  108.                 rm -rf $INST_PATH
  109.             endif
  110.         endif
  111.     else
  112.         set INST_PATH=none
  113.     endif
  114. else
  115.     set INST_PATH=none
  116. endif
  117.  
  118. if ( $INST_PATH == "none" ) then
  119.  
  120. #   Read name of installation directory.
  121.  
  122.     echo " "
  123.     echo "This demo requires $MBYTES_REQ Mbytes of disk space."
  124.  
  125.     LOOP1:
  126.  
  127.     unset INSTDIR_FILESYS
  128.  
  129.     echo " "
  130.     echo "Enter the full path name of an existing directory"
  131.     echo "in which to copy the software (or enter 'q' to quit):  \c"
  132.     set ans=($<)
  133.  
  134. #   Check validity of the path name.  If it contains only a "/",
  135. #   this will cause a divide by zero, and fail.
  136.     set TEST1=`echo $ans | cut -f2 -d"/"`
  137.     if ( ! $#TEST1 ) then
  138.             echo " "
  139.             echo "You cannot use directory /.  Please try again."
  140.             goto LOOP1
  141.     endif
  142.  
  143.     if ( $ans == 'q' ) then
  144.         echo " "
  145.         echo "... Bye."
  146.         sleep 3
  147.         exit
  148.     else if ( $#ans == 0 ) then
  149.         echo " "
  150.         echo "Input error.  Please try again."
  151.         goto LOOP1
  152.     else
  153.  
  154. #       Check validity of the path name again.  It must begin with "/".
  155.         set TEST2=`echo $ans | cut -f2 -d"/" -s`
  156.         if ( ! $#TEST2 ) then
  157.                 echo " "
  158.                 echo "The pathname must begin with /.  Please try again."
  159.                 goto LOOP1
  160.         endif
  161.  
  162.         if ( -d $ans ) then
  163.  
  164.             echo " "
  165.             echo "A $INST_DIR directory will be created in $ans."
  166.             echo "Is this OK (y/n)?:  \c"
  167.             set ans2=($<)
  168.             if ( $ans2 != 'y' ) goto LOOP1
  169.  
  170. #           Determine the space available for the filesystem
  171. #           containing the requested directory.
  172. #
  173.  
  174. #                       Check to see if the directory is actually a link or an
  175. #                       nfs mount and do appropriate checks.
  176.  
  177.                         if ( -l $ans ) then
  178.                                 cd $ans
  179.                                 set CDIR=`pwd`
  180.                                 set KBYTES_AVAIL=`df -k $CDIR | /usr/bin/awk
  181. '{print $5}'`
  182.                         endif
  183.  
  184.                         touch $ans/hmtest
  185.                         if ( ! -r $ans/hmtest ) then
  186.  
  187.                                 echo "Can not write to $ans, please choose
  188. another directory."
  189.                                 goto LOOP1
  190.                         endif
  191.             /bin/rm -f $ans/hmtest
  192.  
  193.  
  194.  
  195. #           First, find all the mounted filesystems.
  196.             set FILESYSTEMS=`df -k | awk '{print $7}' | grep /`
  197.  
  198. #           Now, beginning with the full path name of the
  199. #           requested directory, start stripping off the trailing
  200. #           subdirectory names, and compare this to the existing
  201. #           file system names.  If these match exactly, then we've
  202. #           found the right file system.
  203.  
  204.             set TEST3=`echo $ans | cut -f3 -d"/"`
  205.             if ( ! $#TEST3 ) then
  206.                 set PATH=$ans
  207.             else
  208.                 set PATH=`dirname $ans`
  209.             endif
  210.             LOOP2:
  211.                 foreach FILESYSTEM ($FILESYSTEMS)
  212.  
  213. #                   Don't do the test if $FILESYSTEM == "/"
  214.                     set TEST4=`echo $FILESYSTEM | cut -f2 -d"/"`
  215.                     if ( $#TEST4 != 0 ) then
  216.  
  217.                         if ( $PATH == $FILESYSTEM ) then
  218.                             set INSTDIR_FILESYS=$PATH
  219.                         endif
  220.                     endif
  221.                 end
  222.                 set PATH=`dirname $PATH`
  223.  
  224. #           Continue looping until we've stripped the pathname
  225. #           down to only "/", or until we find the file system.
  226.  
  227.             set LOOPTEST=`echo $PATH | cut -f2 -d"/"`
  228.             if (( $#LOOPTEST != 0 ) && ( ! $?INSTDIR_FILESYS )) goto LOOP2
  229.  
  230.             if ( $?INSTDIR_FILESYS ) then
  231.  
  232. #               Determine the available space
  233.  
  234.                 set KBYTES_AVAIL=`df -k $INSTDIR_FILESYS | /bin/grep
  235. $INSTDIR_FILESYS | /usr/bin/awk '{print $5}'`
  236.  
  237.             else
  238.                 if ( $FILE_STRUCTURE == "new" ) then
  239.                   set KBYTES_AVAIL=`df -k / | /bin/grep / | /usr/bin/awk
  240. '{print $5}'`
  241.                 else
  242.                 echo " "
  243.                 echo "  ERROR:  Can't determine the amount of available disk"
  244.                 echo "          space for the directory you requested."
  245.                 echo " "
  246.                 echo "          Continue anyway (y/n)?  \c"
  247.                 set ans3=($<)
  248.                 if ( $ans3 == 'y' ) then
  249.                     @ KBYTES_AVAIL = ($KBYTES_REQ) + 1
  250.                 else
  251.                     echo " "
  252.                     echo "... Bye."
  253.                     sleep 3
  254.                     exit
  255.                 endif
  256.             endif
  257.        endif
  258.  
  259.             if ( $KBYTES_AVAIL > $KBYTES_REQ ) then
  260.                 if ( -w $ans ) then
  261.  
  262. #                   Success!!!
  263.  
  264.                     set INST_PATH=$ans/$INST_DIR
  265.                     echo " "
  266.                 else
  267.                     echo " "
  268.  
  269.                     echo "Can't write to directory $ans."
  270.                     echo "Please try again."
  271.                     goto LOOP1
  272.                 endif
  273.             else
  274.                 echo " "
  275.                 echo "Not enough space available."
  276.                 echo "Please try again."
  277.                 goto LOOP1
  278.             endif
  279.         else
  280.             echo " "
  281.             echo "Can't find directory $ans."
  282.             goto LOOP1
  283.         endif
  284.     endif
  285.  
  286.     # Check installation directory.
  287.     if ( -d $INST_PATH ) then
  288.         echo " "
  289.         echo "It seems the demo is already installed.  Continue anyway (y/n)?
  290.  \c"
  291.         set ans3=($<)
  292.         if ( $ans3 != 'y' ) then
  293.             echo " "
  294.             echo "... Bye."
  295.             sleep 3
  296.             exit
  297.         endif
  298.  
  299.         rm -rf $INST_PATH
  300.     endif
  301. endif
  302.  
  303. #  Store INST_PATH in a file so it can be communicated to the RemoveIt script.
  304. #
  305. #  First, try to put it in /usr/tmp.  If we can't, then put it in /tmp
  306. #  and in the user's home directory.  If put in /tmp, the file will
  307. #  disappear if the machine is rebooted.  If put in the user's home
  308. #  directory, we won't be able to find it if the user trying to remove
  309. #  the software is not the same as the user who installed it.  Either
  310. #  case isn't very good, but it's the best we can do if we can't write
  311. #  to /usr/tmp.
  312.  
  313. /bin/rm -f /usr/tmp/HOTMIXPATH_$INST_DIR > /dev/null
  314. /bin/rm -f /tmp/HOTMIXPATH_$INST_DIR > /dev/null
  315.  
  316. /bin/rm -f ~/HOTMIXPATH_$INST_DIR > /dev/null
  317.  
  318. if ( -w /usr/tmp ) then
  319.     echo "setenv INST_PATH $INST_PATH" > /usr/tmp/HOTMIXPATH_$INST_DIR
  320.     /bin/chmod 666 /usr/tmp/HOTMIXPATH_$INST_DIR
  321. else
  322.     echo "setenv INST_PATH $INST_PATH" > /tmp/HOTMIXPATH_$INST_DIR
  323.     /bin/chmod 666 /tmp/HOTMIXPATH_$INST_DIR
  324.  
  325.     echo "setenv INST_PATH $INST_PATH" > ~/HOTMIXPATH_$INST_DIR
  326.     /bin/chmod 666 ~/HOTMIXPATH_$INST_DIR
  327. endif
  328.  
  329. #
  330. #-----------------------------------------------------------------------
  331. #
  332. #  Now that we've finally determined INST_PATH, do the installation.
  333. #  In this case, just copy the software and execute the application.
  334.  
  335. echo " "
  336. echo "Installing $MYAPP.  Please wait... \c"
  337.     mkdir $INST_PATH
  338.      cd $INST_PATH/..
  339.         zcat $CD_PATH/finesse.tar.Z | tar xfB - 
  340. echo "Done."
  341. echo " "
  342. echo "To run the demo:"
  343. echo ""
  344. echo "    setenv FINESSEPATH $INST_PATH"
  345. echo ""
  346. echo "Then, move to the $INST_PATH/examples directory"
  347. echo "or one of its subdirectories csh, perl, or sh"
  348. echo "and execute any application."
  349. echo " "
  350. echo "For a nicer appearance of the demos you may set: "
  351. echo ""
  352. echo "     setenv XUSERFILESEARCHPATH $INST_PATH/examples/app-defaults/%N"
  353. echo " "
  354.  
  355. echo "Do you want to run the introductory demo now (y/n)? \c"
  356. set ans=($<)
  357. if ( $ans == 'y' ) then
  358.     setenv FINESSEPATH $INST_PATH
  359.     $INST_PATH/examples/examples_sh
  360. else
  361.     echo "... Bye."
  362.     # sleep 3
  363. endif
  364. echo "Press Enter to exit this window...  \c"
  365. set a = $<
  366.  
  367.